<template>
  <xy-material-card :material="material" @click="clickHandle"></xy-material-card>
</template>

<script>
    import xyMaterialCard from "./MaterialCard";

    /**
     * 物料卡-打印 ，这里只是简单的打印物料信息
     * @author Canaan
     * @date 2019/9/18 14:26.
     */
    export default {
        name: 'printMaterialCard',
        mounted() {

        },
        components: {
            xyMaterialCard
        },
        props: {
            material: {
                type: Object,
                default() {
                    return {
                        id: null,
                        name: null
                    }
                }
            }
        },
        data() {
            return {}
        },
        computed: {},
        methods: {
            clickHandle() {
                this.$alert("正在为您处理...");

                let tagTemplate = this.material.tagTemplate.id;
                this.$ajax.get('tag_template/get/' + tagTemplate).then(response => {
                    if (response.code !== 'ok') {
                        this.$message.error(response.msg);
                        return;
                    }
                    if (response.data.disabled) {
                        this.$message.error("模板不可用");
                        return;
                    }
                    let res = this.$android.printCall({
                        material: this.material
                    }, response.data);

                    if (res.code !== 'ok') {
                        this.$message.error(res.msg);
                    }
                });
            }
        },
        watch: {},
        filters: {},
        beforeDestroy() {

        }
    }
</script>

<style scoped>

</style>
